<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BasePatients {

	protected $m_intId;
	protected $m_strFirstName;
	protected $m_strMiddleName;
	protected $m_strLastName;
	protected $m_strMotherName;
	protected $m_intAge;
	protected $m_charGender;
	protected $m_strBirthDate;
	protected $m_strAddress;
	protected $m_strMaritalStatus;
	protected $m_strOccupaction;
	protected $m_strHomeNumber;
	protected $m_strOfficeNumber;
	protected $m_strMobileNumber;
	protected $m_strEmailAddress;
	protected $m_intPatientId;
	protected $m_intDoctorId;
	protected $m_intPatientTypeId;
	protected $m_intPatientAreaId;
	protected $m_strPatientPhotoPath;
	protected $m_strPatientIdProofPath;
	protected $m_strPatientResidentIdProofPath;
	protected $m_intCreatedBy;
	protected $m_strCreatedOn;
	protected $m_intUpdatedBy;
	protected $m_strUpdatedOn;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_intId;
	}

	public function getFirstName(){
		return $this->m_strFirstName;
	}

	public function getMiddleName(){
		return $this->m_strMiddleName;
	}

	public function getLastName(){
		return $this->m_strLastName;
	}

	public function getMotherName(){
		return $this->m_strMotherName;
	}

	public function getAge(){
		return $this->m_intAge;
	}

	public function getGender(){
		return $this->m_charGender;
	}

	public function getBirthDate(){
		return $this->m_strBirthDate;
	}

	public function getAddress(){
		return $this->m_strAddress;
	}

	public function getMaritalStatus(){
		return $this->m_strMaritalStatus;
	}

	public function getOccupaction(){
		return $this->m_strOccupaction;
	}

	public function getHomeNumber(){
		return $this->m_strHomeNumber;
	}

	public function getOfficeNumber(){
		return $this->m_strOfficeNumber;
	}

	public function getMobileNumber(){
		return $this->m_strMobileNumber;
	}

	public function getEmailAddress(){
		return $this->m_strEmailAddress;
	}

	public function getPatientId(){
		return $this->m_intPatientId;
	}

	public function getDoctorId(){
		return $this->m_intDoctorId;
	}

	public function getPatientTypeId(){
		return $this->m_intPatientTypeId;
	}

	public function getPatientAreaId(){
		return $this->m_intPatientAreaId;
	}

	public function getPatientPhotoPath(){
		return $this->m_strPatientPhotoPath;
	}

	public function getPatientIdProofPath(){
		return $this->m_strPatientIdProofPath;
	}

	public function getPatientResidentIdProofPath(){
		return $this->m_strPatientResidentIdProofPath;
	}

	public function getCreatedBy(){
		return $this->m_intCreatedBy;
	}

	public function getCreatedOn(){
		return $this->m_strCreatedOn;
	}

	public function getUpdatedBy(){
		return $this->m_intUpdatedBy;
	}

	public function getUpdatedOn(){
		return $this->m_strUpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_intId = $Id;
	}

	public function setFirstName( $FirstName ){
		$this->m_strFirstName = $FirstName;
	}

	public function setMiddleName( $MiddleName ){
		$this->m_strMiddleName = $MiddleName;
	}

	public function setLastName( $LastName ){
		$this->m_strLastName = $LastName;
	}

	public function setMotherName( $MotherName ){
		$this->m_strMotherName = $MotherName;
	}

	public function setAge( $Age ){
		$this->m_intAge = $Age;
	}

	public function setGender( $Gender ){
		$this->m_charGender = $Gender;
	}

	public function setBirthDate( $BirthDate ){
		$this->m_strBirthDate = $BirthDate;
	}

	public function setAddress( $Address ){
		$this->m_strAddress = $Address;
	}

	public function setMaritalStatus( $MaritalStatus ){
		$this->m_strMaritalStatus = $MaritalStatus;
	}

	public function setOccupaction( $Occupaction ){
		$this->m_strOccupaction = $Occupaction;
	}

	public function setHomeNumber( $HomeNumber ){
		$this->m_strHomeNumber = $HomeNumber;
	}

	public function setOfficeNumber( $OfficeNumber ){
		$this->m_strOfficeNumber = $OfficeNumber;
	}

	public function setMobileNumber( $MobileNumber ){
		$this->m_strMobileNumber = $MobileNumber;
	}

	public function setEmailAddress( $EmailAddress ){
		$this->m_strEmailAddress = $EmailAddress;
	}

	public function setPatientId( $PatientId ){
		$this->m_intPatientId = $PatientId;
	}

	public function setDoctorId( $DoctorId ){
		$this->m_intDoctorId = $DoctorId;
	}

	public function setPatientTypeId( $PatientTypeId ){
		$this->m_intPatientTypeId = $PatientTypeId;
	}

	public function setPatientAreaId( $PatientAreaId ){
		$this->m_intPatientAreaId = $PatientAreaId;
	}

	public function setPatientPhotoPath( $PatientPhotoPath ){
		$this->m_strPatientPhotoPath = $PatientPhotoPath;
	}

	public function setPatientIdProofPath( $PatientIdProofPath ){
		$this->m_strPatientIdProofPath = $PatientIdProofPath;
	}

	public function setPatientResidentIdProofPath( $PatientResidentIdProofPath ){
		$this->m_strPatientResidentIdProofPath = $PatientResidentIdProofPath;
	}

	public function setCreatedBy( $CreatedBy ){
		$this->m_intCreatedBy = $CreatedBy;
	}

	public function setCreatedOn( $CreatedOn ){
		$this->m_strCreatedOn = $CreatedOn;
	}

	public function setUpdatedBy( $UpdatedBy ){
		$this->m_intUpdatedBy = $UpdatedBy;
	}

	public function setUpdatedOn( $UpdatedOn ){
		$this->m_strUpdatedOn = $UpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into PATIENTS (first_name, middle_name, last_name, mother_name, age, gender, birth_date, address, marital_status, occupaction, home_number, office_number, mobile_number, email_address, patient_id, doctor_id, patient_type_id, patient_area_id, patient_photo_path, patient_id_proof_path, patient_resident_id_proof_path, created_by, created_on, updated_by, updated_on) values ('" . $this->getFirstName() . "', '" . $this->getMiddleName() . "', '" . $this->getLastName() . "', '" . $this->getMotherName() . "', " . $this->getAge() . ", " . $this->getGender() . ", '" . $this->getBirthDate() . "', '" . $this->getAddress() . "', '" . $this->getMaritalStatus() . "', '" . $this->getOccupaction() . "', '" . $this->getHomeNumber() . "', '" . $this->getOfficeNumber() . "', '" . $this->getMobileNumber() . "', '" . $this->getEmailAddress() . "', " . $this->getPatientId() . ", " . $this->getDoctorId() . ", " . $this->getPatientTypeId() . ", " . $this->getPatientAreaId() . ", '" . $this->getPatientPhotoPath() . "', '" . $this->getPatientIdProofPath() . "', '" . $this->getPatientResidentIdProofPath() . "', " . $this->getCreatedBy() . ", now() , " . $this->getUpdatedBy() . ", NULL )");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE PATIENTS set  first_name= '" . $this->getFirstName() . "', middle_name= '" . $this->getMiddleName() . "', last_name= '" . $this->getLastName() . "', mother_name= '" . $this->getMotherName() . "', age= " . $this->getAge() . ", gender= " . $this->getGender() . ", birth_date= '" . $this->getBirthDate() . "', address= '" . $this->getAddress() . "', marital_status= '" . $this->getMaritalStatus() . "', occupaction= '" . $this->getOccupaction() . "', home_number= '" . $this->getHomeNumber() . "', office_number= '" . $this->getOfficeNumber() . "', mobile_number= '" . $this->getMobileNumber() . "', email_address= '" . $this->getEmailAddress() . "', patient_id= " . $this->getPatientId() . ", doctor_id= " . $this->getDoctorId() . ", patient_type_id= " . $this->getPatientTypeId() . ", patient_area_id= " . $this->getPatientAreaId() . ", patient_photo_path= '" . $this->getPatientPhotoPath() . "', patient_id_proof_path= '" . $this->getPatientIdProofPath() . "', patient_resident_id_proof_path= '" . $this->getPatientResidentIdProofPath() . "', created_by= " . $this->getCreatedBy() . ", updated_by= " . $this->getUpdatedBy() . ",updated_on = now()  where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM patients WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'patients'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}